package com.yingpai.fitness.dvp_2_0.main.activity.dynamic;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.yingpai.fitness.R;
import com.yingpai.fitness.dvp_2_0.common.activity.CommonActivity;
import com.yingpai.fitness.dvp_2_0.common.adapter.BaseAdapterHelper;
import com.yingpai.fitness.dvp_2_0.common.adapter.QuickAdapter;
import com.yingpai.fitness.dvp_2_0.common.util.constant.Contacts;
import com.yingpai.fitness.dvp_2_0.main.widget.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by ASUS on 2019/2/25.
 */

public class Dvp_2_1_DynamicDetailActivity extends CommonActivity implements OnRefreshLoadMoreListener {

    @BindView(R.id.right_tv)
    TextView rightTv;
    @BindView(R.id.empty)
    LinearLayout empty;
    @BindView(R.id.listview)
    ListView listview;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    private QuickAdapter<String> quickAdapter;

    List<String> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusFlag(Contacts.NORMAL_STATUS);
        setContentView(R.layout.dvp_2_1_activity_dynamic_detail);

    }

    @Override
    protected void initView() {

        list.add("http://c.hiphotos.baidu.com/zhidao/pic/item/562c11dfa9ec8a1359aa88b6f103918fa0ecc030.jpg");
        list.add("http://c.hiphotos.baidu.com/zhidao/pic/item/562c11dfa9ec8a1359aa88b6f103918fa0ecc030.jpg");
        list.add("http://c.hiphotos.baidu.com/zhidao/pic/item/562c11dfa9ec8a1359aa88b6f103918fa0ecc030.jpg");

        setTitle("动态详情");
        Drawable drawableLeft = getResources().getDrawable(
                R.mipmap.new_camera);
        rightTv.setCompoundDrawablesWithIntrinsicBounds(drawableLeft,
                null, null, null);
        refreshLayout.setOnRefreshLoadMoreListener(this);
        refreshLayout.setRefreshHeader(new MaterialHeader(context).setColorSchemeResources(R.color.common_color));

        quickAdapter = new QuickAdapter<String>(context, R.layout.item_dynamic_detail) {
            @Override
            protected void convert(BaseAdapterHelper helper, String item) {

                Banner banner = helper.getView(R.id.banner);
                TextView count_num = helper.getView(R.id.count_num);
                count_num.setText("3");
                final TextView current_num = helper.getView(R.id.current_num);
                banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                    @Override
                    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                    }

                    @Override
                    public void onPageSelected(int position) {
                        current_num.setText(position+1 +"");
                    }

                    @Override
                    public void onPageScrollStateChanged(int state) {

                    }
                });

                banner.setImages(list)
                        .setBannerStyle(BannerConfig.NOT_INDICATOR)
                        .setImageLoader(new GlideImageLoader())
                        .start();

                CircleImageView head_photo = helper.getView(R.id.head_photo);
                head_photo.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(Dvp_2_1_PersonalDetailActivity.class);
                    }
                });

                helper.getView(R.id.comment_count_ll).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(DynamicCommentActivity.class);
                    }
                });
            }
        };

        listview.setAdapter(quickAdapter);
    }

    @Override
    protected void initData() {

        quickAdapter.add("");
        quickAdapter.add("");
        quickAdapter.add("");
        quickAdapter.add("");
        quickAdapter.add("");
        quickAdapter.add("");

        quickAdapter.notifyDataSetChanged();
    }

    @Override
    @OnClick({R.id.right_tv, R.id.empty})
    public void onViewClicked(View view) {
        super.onViewClicked(view);
        switch (view.getId()) {
            case R.id.right_tv:
                startActivity(Dvp_2_1_PublishActivity.class);
                break;
            case R.id.empty:
                break;
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

    }
}
